﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SGTD.Entidades;
using SGTD.COM;

namespace SGTD.Controllers
{
    public class PersonaController : Controller
    {
        ////
        //// GET: /Persona/

        static int persona;


        public ActionResult Registrar()
        {
            return View();
        }

        //public ActionResult Registrar2()
        //{
        //    return View();
        //}


        public ActionResult Personal()
        {
            return PartialView();
        }

        [HttpPost()]

        public ActionResult Personal(clsPersona p)
        {
            if (ModelState.IsValid)
            {
                Int32 exito;
                clsGestorPersona com = new clsGestorPersona();
                exito = com.registrarPersona(p);
                if (exito != 0)
                {
                    persona = exito;
                    //Session["Persona"] = p.IdPersona;                
                    return View("Exito");
                }
                else
                    return PartialView();
            }
            return PartialView(p);
        }

        public ActionResult Corporativo()
        {
            clsGestorArea comArea = new clsGestorArea();
            clsGestorCargo comCargo = new clsGestorCargo();
            clsGestorTurno comTurno = new clsGestorTurno();
            List<clsArea> listaArea = comArea.ListarArea();
            List<clsCargo> listaCargo = comCargo.listar();
            List<clsTurno> listaTurno = comTurno.listarTurno();

            ViewData["Area"] = new SelectList(listaArea, "IdArea", "NombreArea");

            ViewData["Cargo"] = new SelectList(listaCargo, "IdCargo", "Nombre");

            ViewData["Turno"] = new SelectList(listaTurno, "IdTurno", "Nombre");

            return PartialView();
        }

        [HttpPost()]

        public ActionResult Corporativo(clsEmpleado e)
        {

            e.Persona = persona;

            Boolean exito = false;
            if (e.Persona > 0)
            {
                clsGestorEmpleado com = new clsGestorEmpleado();
                exito = com.registrarEmpleado(e);
                if (exito)
                    return View("Exito");
                else
                    return PartialView(e);
            }
            else
            {
                return PartialView("Personal");
            }
        }      
        
    }
}
